CPP = g++
CPPFLAGS = -std=c++0x -pthread `pkg-config --cflags xmms2-client sqlite3`
LDFLAGS = -lxmmsclient -lxmmsclient++ -ldiscid -lsqlite3
SOURCES = $(wildcard *.cpp)
INCLUDES = $(wildcard *.hpp *.h)
OBJDIR = objs
OBJS = $(patsubst %.cpp, $(OBJDIR)/%.o, $(SOURCES))
EXECUTABLE = xmms2-cdinfo
DEPDIR = deps
df = $(DEPDIR)/$(*F)
SUFFIXES += .d

release: $(OBJS)
	@echo Linking $@ $(EXECUTABLE) ...
	@$(CPP) $(OBJS) -o $(EXECUTABLE) $(LDFLAGS)

debug: CPPFLAGS += -ggdb -DDEBUG
debug: $(OBJS)
	@echo Linking $@ $(EXECUTABLE) ...
	@$(CPP) $(OBJS) -o $(EXECUTABLE) $(LDFLAGS)

objs/%.o: %.cpp
	@if [ ! -e $(OBJDIR) ]; then mkdir $(OBJDIR); fi
	@if [ ! -e $(DEPDIR) ]; then mkdir $(DEPDIR); fi
	@echo Compiling $< ...
	@$(CPP) -c $(CPPFLAGS) -o $@ $< -MD -MF $(df).d
	@cp $(df).d $(df).P; \
	sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
	    -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
	rm -f $(df).d

-include $(SOURCES:%.cpp=$(DEPDIR)/%.P)

clean:
	@rm -rf $(OBJDIR) $(DEPDIR) $(EXECUTABLE)
